/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.openbrew.openbrewrf;

import com.openbrew.openbrewrf.views.POSSupplyView;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author chapmand
 */
@Entity
@Table(name = "posGlassWare")
@XmlRootElement
public class POSGlassWare implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "glassWareID")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 250)
    @Column(name = "description")
    private String glassWareDescription;
    @Basic(optional = false)
    @NotNull
    @Column(name = "sizeInOunces")
    private float size;
    @Basic(optional = false)
    @NotNull
    @Column(name = "prePackaged")
    private boolean prePackaged;
    @Basic(optional = false)
    @NotNull
    @Column(name = "refillable")
    private boolean refillable;
    @Basic(optional = false)
    @NotNull
    @Column(name = "loyaltyGrowler")
    private boolean loyaltyGrowler;
    @Basic(optional = false)
    @NotNull
    @Column(name = "loyaltyPoints")
    private boolean loyaltyPoints;
    @JoinColumn(name = "refillSupply", referencedColumnName = "SupID", nullable=true)
    @ManyToOne(optional=true)
    private POSSupplyView glassWareSupply;
    @OneToMany(mappedBy = "glassware")
    private Collection<POSProductServingType> servingTypeCollection;
    @OneToOne(mappedBy="glassware")
    private POSSetup posSetup;
    @OneToOne(mappedBy="glassware")
    private POSProdTemplate prodTemplate;

    public POSGlassWare() {
    }

    public POSGlassWare(Integer id) {
        this.id = id;
    }

    public POSGlassWare(Integer id, String glassWareDescription, float size, boolean prePackaged, boolean refillable) {
        this.id = id;
        this.glassWareDescription = glassWareDescription;
        this.size = size;
        this.prePackaged = prePackaged;
        this.refillable = refillable;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getGlassWareDescription() {
        return glassWareDescription;
    }

    public void setGlassWareDescription(String glassWareDescription) {
        this.glassWareDescription = glassWareDescription;
    }

    public float getSize() {
        return size;
    }

    public void setSize(float size) {
        this.size = size;
    }

    public boolean isPrePackaged() {
        return prePackaged;
    }

    public void setPrePackaged(boolean prePackaged) {
        this.prePackaged = prePackaged;
    }

    public boolean isRefillable() {
        return refillable;
    }

    public void setRefillable(boolean refillable) {
        this.refillable = refillable;
    }

    public boolean isLoyaltyGrowler() {
        return loyaltyGrowler;
    }

    public void setLoyaltyGrowler(boolean loyaltyGrowler) {
        this.loyaltyGrowler = loyaltyGrowler;
    }

    public boolean isLoyaltyPoints() {
        return loyaltyPoints;
    }

    public void setLoyaltyPoints(boolean loyaltyPoints) {
        this.loyaltyPoints = loyaltyPoints;
    }

    public POSSupplyView getSupply() {
        return glassWareSupply;
    }

    public void setSupply(POSSupplyView glassWareSupply) {
        if(glassWareSupply != null && glassWareSupply.getSupID() != null){
            this.glassWareSupply = glassWareSupply;
        }
    }

    @XmlTransient
    public POSSetup getPOSSetup() {
        return posSetup;
    }

    public void setPOSSetup(POSSetup posSetup) {
        this.posSetup = posSetup;
    }

    @XmlTransient
    public POSProdTemplate getProdTemplate() {
        return prodTemplate;
    }

    public void setProdTemplate(POSProdTemplate prodTemplate) {
        this.prodTemplate = prodTemplate;
    }

    @XmlTransient
    public Collection<POSProductServingType> getServingTypeCollection() {
        return servingTypeCollection;
    }

    public void setServingTypeCollection(Collection<POSProductServingType> servingTypeCollection) {
        this.servingTypeCollection = servingTypeCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof POSGlassWare)) {
            return false;
        }
        POSGlassWare other = (POSGlassWare) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.posglassware[ id=" + id + " ]";
    }
}
